#!/bin/sh

################################################################################
# Copyright 1999-2010 by Nice, srl.,
# Via Marchesi di Roero, 1
# 14020 Cortanze (AT) - ITALY
# All rights reserved.
#
# This software is the confidential and proprietary information
# of Nice, srl. ("Confidential Information").
# You shall not disclose such Confidential Information
# and shall use it only in accordance with the terms of
# the license agreement you entered into with Nice.
################################################################################

. "${EF_ROOT}/plugins/irods/bin/common"
. "${EF_ROOT}/plugins/fm/fm/backends/common"

if [ -z "$1" ]; then
  fatal "Cannot create archive" "Missing input parameter: current path"
fi

if [ -z "$2" ]; then
  fatal "Cannot list browse action" "Missing input parameter: filename"
fi

_fullpath="$1"
_filename="$2"

# Change to the required directory
${IRODS_ICOMMANDS_DIR}/icd "${_fullpath}" >/dev/null 2>&1
if [ $? -ne 0 ]; then
  fatal "Cannot create archive \"${_fullname}\"" "Cannot access to working directory"
fi

hydrogen_actions() {
cat << EOF
  <ef:item-action id="compress" icon="/${EF_ROOT_CONTEXT}/hydrogen/images/folder-zipper.png">
    <ef:name>Compress...</ef:name>
    <efactions:invoke-javascript>
      fmBrowseFunc.compress("${widgetId}", environment);
    </efactions:invoke-javascript>
  </ef:item-action>
EOF

  # This heuristic should be good enough. Need further testing
cat << EOF
  <ef:item-action id="streaming-download" icon="/${EF_ROOT_CONTEXT}/hydrogen/images/monitor.png">
    <ef:name>Replicate</ef:name>
    <efactions:invoke-javascript>
      fmBrowseFunc.replicate("${widgetId}", environment);
    </efactions:invoke-javascript>
  </ef:item-action>
EOF

}

# emit requested ui actions
case "${EF_CURRENT_UI}" in
  hydrogen) hydrogen_actions ;;
  *) exit 1 ;;
esac

# ex:ts=2:et:
